/*
 * @Descripttion: 
 * @version: 
 * @Author: mmzhang
 * @Date: 2021-07-23 11:03:01
 * @LastEditTime: 2022-07-18 09:45:38
 */
import table from '@/components/dt/table/render.js'
import nameOpt from '@/biz/option/name.js'
import dateOpt from '@/biz/option/date.js'
import houseOpt from '@/biz/option/house.js'
import Opt from '@/components/dt/info/Opt.js'

let _this = null

class Column extends Opt {
  constructor(vm) {
    super()
    _this = vm
    this.build()
  }

  build() {
    this.createAll()
    // type  1 待审核   无审核状态 审核人  审核日期 ['auditResults','auditTime','auditName']
    // 2 已审核
    let columnNew = []

    if (_this.showTab == 1) {
      columnNew = this.all.filter(item => (['auditResults', 'auditTime', 'auditName']
        .indexOf(
          item.field) <= -1))
    } else {
      columnNew = [...this.all]
    }

    this.opts.push(...columnNew)
  }

  createAll() {
    this.all = [{
      title: '签约单编号',
      field: 'orderCode',
      minWidth: 150,
      header: {
        filter: {
          title: '签约单编号',
          key: 'orderCode',
          placeholder: '请输入至少4位签约单编号',
          input: {},
          check: (val) => {
            if (val.orderCode.length < 4) {
              _this.$Message.warning('请输入至少4位签约单编号。')
            }
            return !(val.orderCode.length < 4)
          }
        },
      }
    },
    {
      title: '审核状态',
      field: 'auditResults',
      minWidth: 130,
    },
    {
      field: 'counselorName',
      minWidth: 130,
      header: {
        filter: nameOpt.create({
          key: 'counselorId',
          title: '归属顾问'
        })
      }
    },
    {
      field: 'customerName',
      minWidth: 150,
      title: '客户姓名',
      slots: {
        default: (params, h) => {
          return table.cell.btn(_this, h, {
            title: params.row.customerName,
            event: 'onLinkUser',
            data: params.row
          })
        }
      },
      header: {
        filter: {
          title: '客户姓名',
          key: 'customerName',
          placeholder: '请输入客户姓名',
          input: {},
        },
      }
    },
    {
      title: '客户手机号',
      field: 'customerPhone',
      minWidth: 150,
      header: {
        filter: {
          title: '客户手机号',
          key: 'customerPhone',
          placeholder: '请输入至少4位客户手机号',
          input: {},
          check: (val) => {
            if (val.customerPhone.length < 4) {
              _this.$Message.warning('请输入至少4位客户手机号。')
            }
            return !(val.customerPhone.length < 4)
          }
        },
      }
    },
    {
      title: '签约房源',
      field: 'roomName',
      minWidth: 180,
      header: {
        filter: houseOpt.createRoom({
          key: 'roomId',
          title: '签约房源'
        })
      }
    },
    {
      title: '面积（㎡）',
      field: 'area',
      minWidth: 150,
    },
    {
      field: 'subscriptionDate',
      minWidth: 150,
      title: '签约日期',
      header: {
        filter: dateOpt.range({
          title: '签约日期',
          startKey: 'subscriptionStartDate',
          endKey: 'subscriptionEndDate',
          disabled: (date) => {
            return date.valueOf() > new Date().getTime()
          },
          check: (val) => {
            if (_this.$tool.dateDiff(val.subscriptionStartDate, val
                .subscriptionEndDate).Y >= 2) {
              // 日期最大跨度两年
              _this.$Message.warning('签约日期跨度至多两年。')
            }
            return !(_this.$tool.dateDiff(val.subscriptionStartDate, val
              .subscriptionEndDate).Y >= 2)
          }
        }),
      },
    },
    {
      title: '新增附件数',
      field: 'addAnnexNum',
      minWidth: 150,
    },
    {
      title: '上传日期',
      field: 'annexBackupDate',
      minWidth: 180,
      header: {
        filter: dateOpt.range({
          title: '上传日期',
          startKey: 'annexBackupStartDate',
          endKey: 'annexBackupEndDate',
          disabled: (date) => {
            return date.valueOf() > new Date().getTime()
          },
          check: (val) => {
            if (_this.$tool.dateDiff(val.annexBackupStartDate, val
                .annexBackupEndDate).Y >= 2) {
              // 日期最大跨度两年
              _this.$Message.warning('上传日期跨度至多两年。')
            }
            return !(_this.$tool.dateDiff(val.annexBackupStartDate, val
              .annexBackupEndDate).Y >= 2)
          }
        }),
      }
    },
    {
      title: '审核日期',
      field: 'auditTime',
      minWidth: 180,
      header: {
        filter: dateOpt.range({
          title: '审核日期',
          startKey: 'auditStartDate',
          endKey: 'auditEndDate',
          disabled: (date) => {
            return date.valueOf() > new Date().getTime()
          },
          check: (val) => {
            if (_this.$tool.dateDiff(val.auditStartDate, val
                .auditEndDate).Y >= 2) {
              // 日期最大跨度两年
              _this.$Message.warning('审核日期跨度至多两年。')
            }
            return !(_this.$tool.dateDiff(val.auditStartDate, val
              .auditEndDate).Y >= 2)
          }
        }),
      }
    },
    {
      title: '所属产品',
      field: 'productName',
      minWidth: 180,
      cell: {
        text: {
          lineClamp: 2,
          webkitBoxOrient: 'vertical',
          display: '-webkit-box',
          whiteSpace: 'inherit'
        }
      }
    },
    {
      title: '签约人',
      field: 'contractorName',
      minWidth: 150,
    },
    {
      title: '审核人',
      field: 'auditName',
      minWidth: 120,
    },
    {
      title: '操作',
      fixed: 'right',
      width: 140,
      align: 'center',
      slots: {
        default: (params, h) => {
          let btns = []
          btns.push({
            title: _this.unlocking('0104030300') ? '查看' : '',
            event: 'viewFun',
            data: params.row
          })
          btns.push({
            title: params.row.auditResults == '待审核' && _this.unlocking(
                '0109030100') ?
              '审核' : '',
            event: 'examineFun',
            data: params.row
          })
          return table.cell.btns(_this, h, btns)
        }
      }
    }]
  }

}

export default Column